package cn.iocoder.yudao.module.iot.dal.mysql.room;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.iot.controller.admin.room.vo.IotRoomPageReqVO;
import cn.iocoder.yudao.module.iot.dal.dataobject.room.IotRoomDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * IoT 房间 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface IotRoomMapper extends BaseMapperX<IotRoomDO> {

    default PageResult<IotRoomDO> selectPage(IotRoomPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<IotRoomDO>()
                .likeIfPresent(IotRoomDO::getName, reqVO.getName())
                .eqIfPresent(IotRoomDO::getType, reqVO.getType())
                .eqIfPresent(IotRoomDO::getParentId, reqVO.getParentId())
                .eqIfPresent(IotRoomDO::getUserId, reqVO.getUserId())
                .betweenIfPresent(IotRoomDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(IotRoomDO::getId));
    }

    default List<IotRoomDO> selectListByUserId(Long userId) {
        return selectList(IotRoomDO::getUserId, userId);
    }

    default List<IotRoomDO> selectListByParentId(Long parentId) {
        return selectList(IotRoomDO::getParentId, parentId);
    }

    default List<IotRoomDO> selectListByUserIdAndParentId(Long userId, Long parentId) {
        return selectList(new LambdaQueryWrapperX<IotRoomDO>()
                .eq(IotRoomDO::getUserId, userId)
                .eq(IotRoomDO::getParentId, parentId));
    }

    default IotRoomDO selectByUserIdAndName(Long userId, String name) {
        return selectOne(new LambdaQueryWrapperX<IotRoomDO>()
                .eq(IotRoomDO::getUserId, userId)
                .eq(IotRoomDO::getName, name));
    }

}
